package com.admin.controller;


import com.admin.entity.Station;
import com.admin.entity.StationType;
import com.admin.service.IStationTypeService;
import com.admin.service.impl.StationTypeServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bean.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@RestController
@RequestMapping("/admin/station-type")
public class StationTypeController {
    @Autowired
    private IStationTypeService stationTypeService;

    /**
     * 修改站点禁用启用状态
     * @param
     * @return
     */
    @RequestMapping("/editStationTypeStatus")
    public ResponseBean editStationTypeStatus(@RequestParam Map map) {
        StationType s=stationTypeService.getById((String)map.get("getdata[stationTypeId]"));
        if("禁用".equals(s.getStationTypeStatus())){
            s.setStationTypeStatus("启用");
        }else{
            s.setStationTypeStatus("禁用");
        }
        boolean f = stationTypeService.updateById(s);
        int code=f?200:500;
        return new ResponseBean(code,null,s);
    }
    /**
     * 分页查询所有站点类型
     *
     * @param page
     * @param limit
     * @param stationTypeName
     * @return
     */
    @RequestMapping("/chastationtype")
    public ResponseBean FYcha(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, String stationTypeName) {
        IPage result = stationTypeService.FYcha(page, limit, stationTypeName);
        return new ResponseBean(0,result.getTotal(),result.getRecords());
    }
    /**
     * 新增站点类型并判断数据是否重复
     *
     * @param
     * @return
     */

    @RequestMapping("/addstationtype")
    public ResponseBean addstation(StationType stationType) {
        StationType s=stationTypeService.selectAndAddType(stationType);
        if(s!=null){
            return new ResponseBean(400,0,"数据重复");
        }
        boolean n = stationTypeService.save(stationType);
        int code = n ? 200 : 500;
        return new ResponseBean(code, 0, null);
    }

    /**
     * 查询所有站点类型
     * @return
     */
    @RequestMapping(value = "/query/AllStationType",method = RequestMethod.GET)
    public ResponseBean queryAllStationType(){
        List<StationType> list=stationTypeService.list();
        return new ResponseBean(200,"查询成功",list);
    }
    /**
     * 查询所有未被禁用站点类型
     * @return
     */
    @RequestMapping(value = "/AllStationType",method = RequestMethod.GET)
    public ResponseBean AllStationType(){
        QueryWrapper q=new QueryWrapper();
        q.eq("station_type_status","启用");
        List list=stationTypeService.list(q);
        return new ResponseBean(200,"查询成功",list);
    }

    /**
     * 编辑站点的类型
     * @param s
     * @return
     */
    @RequestMapping("/editStationType")
    public ResponseBean editStationType(StationType s){
        if(stationTypeService.editAddSelect(s)!=null){
            return new ResponseBean(400,0,"数据重复");
        }
        boolean f=stationTypeService.updateById(s);
        int code=f?200:500;
        return new ResponseBean(code,0,null);
    }
    /**
     * 主题管理分页查询所有记录  根据名称查询
     * @param map
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/zhuTiFindAll")
    public ResponseBean zhuTiFindAll(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit,@RequestParam Map map) {
        IPage ipage = stationTypeService.zhuTiFindALL(page, limit,map);
        return new ResponseBean(0, ipage.getTotal(), ipage.getRecords());

    }
}
